﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;
namespace DAO
{
   public class HangVeDAO 
    {
       public List<HangVeDTO> GetAll()
       {
           String sql = " select * ";
           sql += "from HangVe  ";
           SqlConnection conn = DataProvider.ConnectDB("QLVCB.mdf");
           SqlCommand cmd = new SqlCommand(sql, conn);
           SqlDataReader reader = cmd.ExecuteReader();
           List<HangVeDTO> ds = new List<HangVeDTO>();
           while (reader.Read())
           {
               HangVeDTO hangve = new HangVeDTO();
               hangve.MaHangVe = reader.GetString(0);
               hangve.TenHangVe = reader.GetString(1);
               ds.Add(hangve);
           }
           conn.Close();
           return ds;

       }
       public HangVeDTO GetChitiet(string tb, string hv)
       {
           String sql = "SELECT hv.MaHangVe,hv.TenHangVe,dg.MaTuyenBay,dg.DonGia";
           sql += " from HangVe hv, DonGia dg";
           sql += " where dg.MaHangVe like '%" + hv + "%' and dg.MaTuyenBay like '" + tb + "' and hv.MaHangVe=dg.MaHangVe";
          // "danhdiem like '" & txtdanhdiem.Text & "%'"
           SqlConnection conn = DataProvider.ConnectDB("QLVCB.mdf");
           SqlCommand cmd = new SqlCommand(sql, conn);
           SqlDataReader reader = cmd.ExecuteReader();
            HangVeDTO hangve = new HangVeDTO();
           while (reader.Read())
           {
              
               hangve.MaHangVe = reader.GetString(0);
               hangve.TenHangVe = reader.GetString(1);
               hangve.TuyenBay = reader.GetString(2);
               hangve.DonGia = reader.GetDouble(3).ToString();
              
           }
           conn.Close();
           return hangve; 
  
       }
    }
}
